package com.ruoyi.web.controller.work;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.work.domain.WorkFill;
import com.ruoyi.work.domain.WorkFillBatch;
import com.ruoyi.work.service.IWorkCheckService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: MMDZ
 * @Desc: TODO 工时审核
 */
@RestController
@RequestMapping("/work/check")
public class WorkCheckController extends BaseController {

    @Autowired
    private IWorkCheckService workCheckService;

    /**
     * 查询个人的审核列表
     *
     * @param fill
     * @return
     */
    @PreAuthorize("@ss.hasPermi('work:check:list')")
    @GetMapping("/list")
    public TableDataInfo list(WorkFill fill) {
        startPage();
        List<WorkFill> list = workCheckService.selectCheckListByUserId(fill);
        return getDataTable(list);
    }

    /**
     * 审核通过
     *
     * @param fill
     * @return
     */
    @PreAuthorize("@ss.hasPermi('work:check:pass')")
    @Log(title = "审核通过", businessType = BusinessType.UPDATE)
    @PostMapping("/pass")
    public AjaxResult pass(@RequestBody WorkFill fill) {
        return toAjax(workCheckService.updateStatePass(fill));
    }

    /**
     * 批量 审核通过
     *
     * @param batch
     * @return
     */
    @PreAuthorize("@ss.hasPermi('work:check:pass')")
    @Log(title = "批量审核通过", businessType = BusinessType.UPDATE)
    @PostMapping("/batchPass")
    public AjaxResult batchPass(@RequestBody WorkFillBatch batch) {
        return toAjax(workCheckService.updateBatchStatePass(batch.getFills()));
    }

    /**
     * 审核不通过，回退
     *
     * @param fill
     * @return
     */
    @PreAuthorize("@ss.hasPermi('work:check:rollback')")
    @Log(title = "审核回退", businessType = BusinessType.UPDATE)
    @PostMapping("/rollback")
    public AjaxResult rollback(@RequestBody WorkFill fill) {
        return toAjax(workCheckService.updateStateRollback(fill));
    }
}
